package server;

import java.io.IOException;

/**
 * Used to start the Server
 * @author Andreas Mair
 *
 */
public class ServerMain 
{
	public static void main(String[]args)
	{
		if(args.length!=1)
		{
			System.out.println ("Usage:"); 
		    System.out.println ("java Server <tcpPort>"); 
		}
		else
		{
			
			try
			{
				Server server=new Server(args[0]);
				Thread serverThread=new Thread(server);
				serverThread.start();
				try 
				{
					System.in.read();
					System.out.println("Enter was pressed, Server Thread will be stopped...");
					server.stop();
				}
				catch (IOException e) 
				{
					System.out.println("IOException occured while listening on stdin "+e.getMessage());
				}
			}
			catch(NumberFormatException ex)
			{
				System.out.println("tcpPort has to be numeric!");
			}
		}
	}

}
